package com.allwees.bs.c.module.order.repository;

import com.allwees.bs.c.module.base.repository.BaseRepository;
import com.allwees.bs.c.module.order.entity.CartItemEntity;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.Date;
import java.util.List;
import java.util.Set;

public interface CartItemRepository extends BaseRepository<CartItemEntity, Integer> {
    @Query("SELECT ci from CartItemEntity ci WHERE ci.cartUuid=:cartUuid ORDER BY ci.id DESC")
    List<CartItemEntity> getByCartId(@Param("cartUuid") String cartUuid);

    @Query("SELECT ci from CartItemEntity ci WHERE ci.cartUuid=:cartUuid AND ci.skuUuid=:skuUuid")
    CartItemEntity findByCartAndSku(@Param("cartUuid") String cartUuid, @Param("skuUuid") String skuUuid);

    @Query("from CartItemEntity ci WHERE ci.updatedAt < :updateAtTo AND ci.updatedAt > :updateAtFrom")
    Set<CartItemEntity> findNotifyCartUuids(@Param("updateAtFrom") Date updateAtFrom, @Param("updateAtTo") Date updateAtTo);

    List<CartItemEntity> findAllByCartUuid(String cartUuid);
}
